package com.htandroid.htandroid.aty;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.htandroid.htandroid.R;
import com.htandroid.htandroid.entity.Htzc_Pvouch;
import com.htandroid.htandroid.entity.Htzc_Pvouchs;
import com.htandroid.htandroid.sys.base_index;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lkp on 2015/11/29.
 */
public class zcpd_detaillist extends base_index {
    private ArrayList<Htzc_Pvouchs> zcpdlist_detail;
    private Htzc_Pvouch zcpdtitle;
    private String icurrentrow;//记录上一页的当前行
    private String listtype = "0";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAbContentView(R.layout.layout_zcpd_detaillist);
        initview("资产盘点明细");
        initview2();
        createrl(zcpdlist_detail);
    }

    //初始化2
    @Override
    public void initview2() {
        titleBar.getLogoView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                Intent intent = new Intent();
                intent.putExtra("listrow", icurrentrow);
                //因为数据可能发生变化，所以需要把数据返回
                bundle.putSerializable("detaillist", zcpdlist_detail);
                bundle.putSerializable("zcpdtitle", zcpdtitle);
                intent.putExtras(bundle);
                setResult(R.layout.layout_zcpd_detaillist / 300000, intent);  //设置返回结果
                finish();
            }
        });

        //获取传递的对象参数
        zcpdlist_detail = (ArrayList<Htzc_Pvouchs>) getIntent().getSerializableExtra("detaillist");
        zcpdtitle = (Htzc_Pvouch) getIntent().getSerializableExtra("zcpdtitle");
        icurrentrow = getIntent().getExtras().getString("currentrow");
        listtype = getIntent().getExtras().getString("listtype");

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle bundle = new Bundle();
                Intent intent = new Intent();
                intent.putExtra("listrow", icurrentrow);
                //因为数据可能发生变化，所以需要把数据返回
                bundle.putSerializable("detaillist", zcpdlist_detail);
                bundle.putSerializable("zcpdtitle", zcpdtitle);
                intent.putExtras(bundle);
                setResult(R.layout.layout_zcpd_detaillist / 300000, intent);  //设置返回结果
                finish();
            }
        });
    }

    public void createrl(ArrayList<Htzc_Pvouchs> czcpdlists) {
        adatperDataList.clear();
        ArrayList<Map<String, Object>> dataListForInit = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < czcpdlists.size(); i++) {
            //增加一个行选择状态初始化
            if (i == Integer.valueOf(icurrentrow)) {
                sa.getIsSelected().put(i, true);
            } else {
                sa.getIsSelected().put(i, false);
            }
            Htzc_Pvouchs pvouchs = new Htzc_Pvouchs();
            pvouchs = czcpdlists.get(i);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("index", (i + 1));
            map.put("cvouchid", "资产编码：" + pvouchs.getScardnum());
            map.put("cdept", "资产名称：" + pvouchs.getSassetnum());
            map.put("cnocheckreason", "　　部门：" + pvouchs.getSdeptname());
            if (!pvouchs.getLnum().equals("0")) {
                map.put("ddate", "是否盘到：　是");
            } else {
                map.put("ddate", "是否盘到：　否");
            }
            //更多数据
            map.put("data5", "　　规格：" + pvouchs.getsStyle());
            map.put("data6", "　　原值：" + pvouchs.getDblvalue());
            map.put("data7", "存放地点：" + pvouchs.getSsite());
            map.put("data8", "盘点说明：" + pvouchs.getCreason());
            dataListForInit.add(map);
        }
        toolDataProvider.initData(dataListForInit);
        loadList();
        //mHandler.sendEmptyMessage(LIST_GET_FIRST_PAGE); //加载完毕发送指令显示第一页
        //swipeRefreshLayout.setRefreshing(false);
    }
}
